<template>
	<view class="rectify-container">
		<check-item @detail="goCheck" v-if="checkList" :isShowHandle="false" :isShowArrow="true" :check-list="checkList"></check-item>
		<view v-else>
			<van-empty description="暂无记录" />
		</view>
		<uni-load-more v-if="checkList && checkList.length >= 10" :status="status" />
	</view>
</template>

<script>
	import CheckItem from '../components/checkItem.vue'
	import dayjs from 'dayjs'
	export default {
		components: {
			CheckItem
		},
		data() {
			return {
				status: 'more',
				checkList: [],
				params: {
					所属网格id: null,
					网格员id: null,
					巡检状态: 0,
					pagination: {
						current: 1,
						pageSize: 10
					},
					sorter: {
						field: "id",
						order: 1
					}
				},
			}
		},
		onReachBottom() {
			if(this.status !== 'noMore' && this.checkList) {
				this.status = 'loading'
				this.getMoreCheckTask()
			}
		},
		onLoad() {
			this.params.所属网格id = uni.getStorageSync('gridInfo').所属网格id
			this.params.网格员id = uni.getStorageSync('gridInfo').id
			// this.params.网格员 = uni.getStorageSync('userInfo').人员姓名
			this.getCheckTask()
		},
		methods: {
			goCheck(item) {
				if(item['巡检状态'] === 3) {
					uni.navigateTo({
						url: '../checkRecordDetail/checkRecordDetail?item=' + JSON.stringify(item)
					})
				}else {
					uni.navigateTo({
						url: '../checkList/checkList?item=' + JSON.stringify(item)
					})
				}
			},
			getCheckTask() {
				this.params.pagination.current = 1
				this.$http.post('gridSystem/inspection/list', this.params).then(res => {
					if (res.code === 10000) {
						console.log(res)
						this.checkList = res.data.list
						this.total = res.data.total
					}
				})
			},
			getMoreCheckTask() {
				this.params.pagination.current++
				this.$http.post('gridSystem/inspection/list', this.params).then(res => {
					if(res.code === 10000){
						if(res.data.list !== null) {
							this.checkList = this.checkList.concat(res.data.list)
						}
						// this.checkList = this.checkList && this.checkList.concat(res.data.list)
						if(this.checkList.length === res.data.total){
							this.status = 'noMore'
						}
					}
				})
			}
		}
	}
</script>

<style lang="scss">
	.van-empty {
		background-color: #fff;
	}
	.rectify-container {
		padding-top: 20rpx;
		background-color: #f5f5f5;
		// padding-bottom: 20rpx;
	}
</style>
